/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef IE_EXP_EPUB201_H_
#define IE_EXP_EPUB201_H_

// External includes
#include <gsf/gsf-output-stdio.h>
#include <gsf/gsf-outfile.h>
#include <gsf/gsf-outfile-zip.h>
#include <gsf/gsf-output.h>
#include <gsf/gsf-libxml.h>
#include <vector>

// Abiword includes
#include <ie_exp.h>
#include <ut_string.h>
#include <ut_string_class.h>
#include <ut_bytebuf.h>
#include <ut_hash.h>
#include <ut_vector.h>
#include <ut_assert.h>

// EPUB filter includes
#include "EPUB_Document.h"
#include "ie_exp_EPUB201_Listener.h"

#define EPUB_MIMETYPE "application/epub+zip"


class IE_Exp_EPUB201 : public IE_Exp {

public:
	IE_Exp_EPUB201(PD_Document * pDocument);
	virtual ~IE_Exp_EPUB201();

protected:
	virtual UT_Error _writeDocument();

private:
	GsfOutfile *m_outputFile;
	GsfOutput *oebpsDir;
	GsfOutput *m_imagesDir;
};

/**
 * Writes document to OPS files
 */
class EPUB201_StructureWriter{
private:
	/**
	 * Returns vector of document elements in correct traversing order.
	 * Non-recursive
	 */
	static std::vector<EPUB_Shared_Element>* _CreateTrace(EPUB_Shared_Document pDocument);
public:
	/**
	 * Writes document styles to the "css" folder
	 */
	static bool WriteStyles(PD_Document* pDocument, GsfOutput* cssDir);
	/**
	 * Writes document structure into "OEBPS" folder
	 */
	static bool WriteStructure(EPUB_Shared_Document pDocument,
			GsfOutput* contentDir);
	/**
	 * Writes embedded images into selected image dir
	 */
	static bool WriteImages(EPUB_Shared_Document pDocument, GsfOutput* imagesDir);


};

/**
 * Writes document table of contents and metadata to OCF container. Also
 * creates packaging information (".opf" file)
 *
 */
class EPUB201_ContainerWriter{
public:
	/**
	 * Writes document metadata to EPUB "META-INF" folder (container.xml)
	 */
	static bool WriteMetadata(PD_Document* pDocument, GsfOutput* metadataDir);
	/**
	 * Writes table of contents to EPUB ".ncx" file
	 */
	static bool WriteTOC(PD_Document* pDocument, GsfOutput* contentsDir);
	/**
	 * Writes packaging information(".opf") to EPUB "OEBPS" folder
	 */
	static bool WritePackaging(PD_Document* pDocument, GsfOutput* opsDir);

};

#endif /* IE_EXP_EPUB201_H_ */
